<template>
  <div class="app-container">
      <div class="filter-container">
        <el-button class="filter-item" type="primary" v-waves icon="el-icon-plus" @click="clearLogs">清空日志</el-button>        
        <el-input @keyup.enter.native="handleFilter" style="width: 200px;" class="filter-item" placeholder="日志内容" v-model="filters.like$content"></el-input>       
        <el-input @keyup.enter.native="handleFilter" style="width: 200px;" class="filter-item" placeholder="IP地址" v-model="filters.like$ipAddr"></el-input>       
        <el-button class="filter-item" type="primary" v-waves icon="el-icon-search" @click="handleFilter">搜索</el-button>
        <el-button class="filter-item" type="primary"  v-waves icon="el-icon-document" @click="exportExcelFile">导出</el-button>
      </div>
      <el-table :data="list" @sort-change="sortChange" v-loading="listLoading" element-loading-text="给我一点时间" border fit highlight-current-row
      style="width: 100%">
        <el-table-column align="center" type="index" label="序号" width="80">
        </el-table-column>
        <el-table-column  prop="operator" align="center" label="操作人" width="120">
          <template slot-scope="scope">
            <span>{{scope.row.operator}}</span>
          </template>
        </el-table-column>
        <el-table-column  prop="ipAddr" align="center" label="IP地址" width="120">
          <template slot-scope="scope">
            <span>{{scope.row.ipAddr}}</span>
          </template>
        </el-table-column>
        <el-table-column  prop="content" align="center" label="操作内容" width="320">
          <template slot-scope="scope">
            <span>{{scope.row.content}}</span>
          </template>
        </el-table-column>
        <el-table-column  prop="createTime" align="center" label="操作时间" width="180">
          <template slot-scope="scope">
            <span>{{scope.row.createTime}}</span>
          </template>
        </el-table-column>
        
        <el-table-column align="center" label="操作" width="200" class-name="small-padding">
          <template slot-scope="scope">
            <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination-container">
      <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page.sync="params.page"
        :page-sizes="[10,20,30,50]" :page-size="params.limit" layout="total, sizes, prev, pager, next, jumper" :total="total">
      </el-pagination>
    </div>
  </div>
</template>

<script>

export default {
  name:"op-log",
  props:{ 
    logType:{
      type:Number,
      default:1
    }
  },
  
  data() {
    return {
        filters:{

        }
    };
  },
  created() {
    this.init("op_log",1);
    this.$model.where({
       'log_type':this.logType
    })
    this.loadData();
  },
  methods: {
    clearLogs(){
       this.$$comfirm('确认清空日志吗？',()=>{
         this.$post('/admin/op_log/clearLogs',{
           logType:this.logType
         }).then(()=>{
           this.$$notify();
           this.loadData();
         })
       })
    },
    exportExcelFile() {
      this.exportExcel({
        title: "操作日志",
        fields: [
            {field:'operator',title:'操作人'}
            ,
            {field:'ipAddr',title:'IP地址'}
            ,
            {field:'content',title:'操作内容'}
            ,
            {field:'createTime',title:'操作时间'}
          
        ]
      }).then(info => {
        this.openWin(info);        
      });
    }
  }
};
</script>
